<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\HistoryDatum;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class HistoryDatumController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new HistoryDatum(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('issue');
            $grid->column('lottery_date');
            $grid->column('week');
            $grid->column('red_no');
            $grid->column('blue_no');
            $grid->column('sell_money');
            $grid->column('prize_one_num');
            $grid->column('prize_one_money');
            $grid->column('prize_two_num');
            $grid->column('prize_two_money');
            $grid->column('prize_three_num');
            $grid->column('prize_three_money');
            $grid->column('jackpot');

            $grid->enableDialogCreate();

            $grid->model()->orderBy('id','desc');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->like('issue');
                $filter->like('red_no');
                $filter->date('lottery_date');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new HistoryDatum(), function (Show $show) {
            $show->field('id');
            $show->field('issue');
            $show->field('lottery_date');
            $show->field('week');
            $show->field('red_no');
            $show->field('blue_no');
            $show->field('sell_money');
            $show->field('prize_one_num');
            $show->field('prize_one_money');
            $show->field('prize_two_num');
            $show->field('prize_two_money');
            $show->field('prize_three_num');
            $show->field('prize_three_money');
            $show->field('jackpot');
            $show->field('remark');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new HistoryDatum(), function (Form $form) {
            $form->display('id')->width(4);
            $form->text('issue')->width(4)->type('number')->required();
            $form->date('lottery_date')->required();
            $form->text('week')->width(4)->required();
            $form->text('red_no')->width(4)->type('number')->required();
            $form->text('blue_no')->width(4)->type('number')->required();
            $form->text('sell_money')->width(4)->type('number')->required();
            $form->text('prize_one_num')->width(4)->type('number')->required();
            $form->text('prize_one_money')->width(4)->type('number')->required();
            $form->text('prize_two_num')->width(4)->type('number')->required();
            $form->text('prize_two_money')->width(4)->type('number')->required();
            $form->text('prize_three_num')->width(4)->type('number')->required();
            $form->text('prize_three_money')->width(4)->type('number')->required();
            $form->text('jackpot')->width(4)->type('number')->required();
            $form->textarea('remark');
        });
    }
}
